# -*- coding: utf-8 -*-
# @Time : 2021/9/9 15:09
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : test_shangji.py
# @Project : crm
'''验证搜索功能，根据筛选条件进行'''

from time import sleep
from selenium.webdriver.common.by import By
from selenium import webdriver
from utils.get_cookie import cookie
from utils import util
from selenium.webdriver.support.select import Select

#定位器
tiaojian_locator=(By.CSS_SELECTOR,"#field")
guanxi_locator=(By.CSS_SELECTOR,"#condition")
shoushuokuang_locator=(By.CSS_SELECTOR,"#search")
shoushuo_locator=(By.CSS_SELECTOR,"#dosearch")

#前提条件
cookie=cookie(util.HOST,util.name,util.password)
driver=webdriver.Chrome()
driver.add_cookie(cookie)
driver.get('http://192.168.1.155/crm/index.php?m=business')


#测试用例步骤
try:
    #选择筛选条件
    tiaojian_element=driver.find_element(*tiaojian_locator)
    tiaojian_select=Select(tiaojian_element)
    tiaojian_select.select_by_visible_text("商机名")
    #选择关系
    guanxi_element=driver.find_element(*guanxi_locator)
    guanxi_select=Select(guanxi_element)
    guanxi_select.select_by_visible_text("包含")
    #搜索框输入信息
    driver.find_element(*shoushuokuang_locator).send_keys("食品")
    #点击搜索
    driver.find_element(*shoushuo_locator).click()


except Exception as e:
    raise e
finally:
    sleep(5)
    driver.quit()